package com.hdey.controller.max;


import com.hdey.pojo.max.TbUscSupcla;
import com.hdey.pojo.max.TbUscSupply;
import com.hdey.service.max.TbUscSupplySvs;
import com.hdey.utils.Result;
import com.hdey.vo.SupplyVoForCreate;
import com.hdey.vo.SupplyVoForSearch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/supply")
@Slf4j
public class TbUscSupplyController {

    @Resource
    private TbUscSupplySvs tbUscSupplySvs;

    private String msg;

    @RequestMapping("/searchSupply")
    public Result searchSupply(SupplyVoForSearch supplyVo){
        System.out.println(supplyVo.toString());
        List<TbUscSupply> list= tbUscSupplySvs.searchSupply(supplyVo);
        return Result.success(list,list.size());
    }

    @RequestMapping("/createSupply")
    public Result createSupply(@RequestBody SupplyVoForCreate supply, HttpSession session){
        //System.out.println(supply.toString());

        List<TbUscSupcla> supclaList = (List<TbUscSupcla>)session.getAttribute("supclaList");
        int result = tbUscSupplySvs.createSupply(supply,supclaList);

        if(result > 0){
            msg = "创建成功！";
        }else{
            msg = "系统错误！";
        }
        return Result.success(msg);
    }


}
